package cn.xiaolang.function.string;

import java.text.ParseException;
import java.text.SimpleDateFormat;



public class StringApply {

    /**
     * 按需求处理日期格式
     * @param args
     */
    public static void main(String[] args) {
//        Date date =  new Date();
//        date.setTime(System.currentTimeMillis());
//        String time = new SimpleDateFormat("yyyyMd").format(date);
//        System.out.println(time);
        String dates[] = {"2015-1-11","2015-11-1","2015-10-03","2015-1-2"};
        for(String date:dates){
            String year = date.split("-")[0];
            String month = null;
            String day = null;
            
            if(date.split("-")[1].length() !=2){
                month = "0"+ date.split("-")[1];
            }else{
                month = date.split("-")[1];
            }
            
            if(date.split("-")[2].length()!=2){
                
                day = "0" + date.split("-")[2];
            }else{
                day = date.split("-")[2];
            }
            date = year+month+day;
            System.out.println(date);
        }
        System.out.println("===============================");
        for(int i=0;i<dates.length ;i++){
        	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        	try {
        		System.out.println(simpleDateFormat.format(simpleDateFormat.parse(dates[i])));
			} catch (ParseException e) {
				e.printStackTrace();
			}
        }
    }
}
